//
//  CourseRequestManager.m
//  TrainTree
//
//  Created by wanghui on 2017/9/29.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "CourseRequestManager.h"

@implementation CourseRequestManager

+ (void)getThemeListResponseBlock:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setRequestPath:TrainTreeThemeListURL];
    [[HttpClient shareInstanceClient]GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if ([JSONData[@"c"] intValue] == 0) {
            responseBlock(JSONData,error,dataTask);
        }
    }];
}

+ (void)getLessonListWithThemeId:(NSString *)themeId responseBlock:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setRequestPath:TrainTreeLessonListURL];
    [param setString:themeId forKey:@"themeId"];

    [[HttpClient shareInstanceClient] GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if ([JSONData[@"c"] intValue] == 0) {
            responseBlock(JSONData,error,dataTask);
        } else {
            [SVProgressHUD showErrorWithStatus:@"数据请求失败"];
        }
    }];
}

+ (void)addOrDeleteLessonWithLessonId:(NSString *)lessonId withType:(NSInteger)type responseBlock:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setRequestPath:TrainTreeLessonAddOrDeleteURL];
    [param setNumber:@([lessonId integerValue]) forKey:@"lessonId"];
    [param setNumber:@(type) forKey:@"type"];
    [[HttpClient shareInstanceClient] GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        responseBlock(JSONData,error,dataTask);
    }];
}

+ (void)requestLessonDetailWithLessonId:(NSString *)lessonId reponseBlock:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setRequestPath:TrainTreeLessonDetailURL];
    [param setString:lessonId forKey:@"lessonId"];
    [[HttpClient shareInstanceClient]GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if ([JSONData[@"c"] intValue] == 0) {
            responseBlock(JSONData,error,dataTask);
        } else {
            [SVProgressHUD showErrorWithStatus:@"数据请求失败"];
        }
    }];
}

+ (void)requestAudioVideoWithLessonId:(NSString *)lessonId reponseBlock:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setRequestPath:TrainTreeAudioVideoURL];
    [param setString:lessonId forKey:@"pointId"];
    [[HttpClient shareInstanceClient]GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if ([JSONData[@"c"] intValue] == 0) {
            responseBlock(JSONData,error,dataTask);
        } else {
            [SVProgressHUD showErrorWithStatus:@"数据请求失败"];
        }
    }];
}

+ (void)postStudyRecordReponseBlock:(ResponseData)responseBlock
{
    // 将开始播放和暂停时间取相差秒数
    [CountVideo shareCountVideo].long_time = @([[TimeTool getTimeIntervalWithStartTime:[CountVideo shareCountVideo].start_time endTime:[CountVideo shareCountVideo].end_time] integerValue]);
    
    RequestParam *param = [[RequestParam alloc]init];
    [param setNumber:[CountVideo shareCountVideo].is_over forKey:@"is_over"];
    [param setNumber:[CountVideo shareCountVideo].long_time forKey:@"long_time"];

    [param setString:[CountVideo shareCountVideo].start_time forKey:@"start_time"];
    [param setString:[CountVideo shareCountVideo].end_time forKey:@"end_time"];
    [param setString:[CountVideo shareCountVideo].pointId forKey:@"pointId"];
    [param setRequestPath:TrainTreeAudioRecordURL];

    [[HttpClient shareInstanceClient]PostReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if ([JSONData[@"c"] integerValue] == 0) {
            NSLog(@"请求成功");
        }
    }];

}













@end
